package com.mstore.service;

import java.util.ArrayList;
import java.util.List;

import com.mstore.dao.IPAuthorityDao;
import com.mstore.pojo.IPAuthority;

public class IPAuthorityService {

	private IPAuthorityDao ipAuthorityDao;
	
	/**
	 * 
	 *保存IP访问记录
	 */
	public void addIPAuthority(IPAuthority ipAuthority) {
		ipAuthorityDao.save(ipAuthority);
	}
	
	/**
	 * 
	 * 根据ip、create_time查询ip访问记录
	 */
	public List<IPAuthority> watchIPAuthority(IPAuthority ipAuthority) {
		List<IPAuthority> authorities = new ArrayList<IPAuthority>();
		List<Object> objects = ipAuthorityDao.watchIPAuthority(ipAuthority);
		for (Object object : objects) {
			authorities.add((IPAuthority)object);
		}
		return authorities;
	}
	
	/**
	 * 
	 *根据ip、create_time获取记录数量
	 */
	public int findIPAuthorityCount(IPAuthority ipAuthority) {
		List<Object> objects = ipAuthorityDao.watchIPAuthority(ipAuthority);
		if (objects == null) {
			return 0;
		}
		return objects.size();
	}
	
	/**
	 * 
	 * 修改IP访问次数
	 */
	public void modifyIPAuthorityCount(IPAuthority ipAuthority) {
		ipAuthorityDao.modifyIPAuthorityCount(ipAuthority);
	}

	public IPAuthorityDao getIpAuthorityDao() {
		return ipAuthorityDao;
	}

	public void setIpAuthorityDao(IPAuthorityDao ipAuthorityDao) {
		this.ipAuthorityDao = ipAuthorityDao;
	}
	
}
